import math

import numpy
import matplotlib.pyplot as plt
import scipy.fftpack

if __name__ == '__main__':
    fs = 800e6
    t = numpy.arange(0, (1 / fs * 12800), 1 / fs)

    f = open('E:/PFB/J0437-4715.dada', 'rb')
    data = b''
    f.seek(4096, 0)
    for i in range(0, 3200):
        data += f.read(4)
        f.seek(4, 1)
    data = list(data)
    f.close()
    for index, value in enumerate(data):
        if value > 127:
            data[index] = data[index] - 256

        data[index] += 2 * math.sin(2 * math.pi * 50e6 * t[index])

        data[index] += 2 * math.sin(2 * math.pi * 133e6 * t[index])
        data[index] += 2 * math.sin(2 * math.pi * 167e6 * t[index])

        data[index] += 2 * math.sin(2 * math.pi * 225e6 * t[index])
        data[index] += 2 * math.sin(2 * math.pi * 250e6 * t[index])
        data[index] += 2 * math.sin(2 * math.pi * 275e6 * t[index])

        data[index] += 2 * math.sin(2 * math.pi * 320e6 * t[index])
        data[index] += 2 * math.sin(2 * math.pi * 340e6 * t[index])
        data[index] += 2 * math.sin(2 * math.pi * 360e6 * t[index])
        data[index] += 2 * math.sin(2 * math.pi * 380e6 * t[index])

    xn = scipy.fftpack.fft(data)

    t = numpy.arange(0, (fs + fs/12799), (fs/12799)) + 1182e6
    plt.plot(t, abs(xn/12800))
    plt.show()
